<template>
  <div class="r-msg-box page-bgBack">
    <div class="backBtn-box">
      <a-button @click="$router.go(-1)"> <a-icon type="left" />返回 </a-button>
    </div>

    <rTitle :tit="postName">
      <div slot="left" style="margin-left: -18px">
        <div class="r-status" :style="{ background: primaryColor }" v-if="this.isCancel === 2">招聘中</div>
        <div class="r-status" v-else>已关闭</div>
      </div>
      <div slot="right">
        <a-button
          @click="close('打开职位')"
          v-if="isCancel === 1"
          :disabled="this.dataJson.companyUnitsVO == null"
          style="margin-right: 12px"
          >打开职位</a-button
        >
        <a-button
          @click="close('关闭职位')"
          v-if="isCancel === 2"
          :disabled="this.dataJson.companyUnitsVO == null"
          style="margin-right: 12px"
          >关闭职位</a-button
        >
        <a-button type="primary" @click="onEdit" style="margin-right: 12px">编辑</a-button>
        <a-button type="primary" @click="onShare" v-if="this.isCancel === 2">生成岗位链接</a-button>
      </div>
    </rTitle>
    <div class="r-msg-status">
      <div class="s-item" v-for="(item, index) in numArr" :key="item.type">
        <div class="s-item-t">{{ item.name }}</div>
        <div class="s-item-b">{{ item.num }}</div>
        <div class="s-item-line" v-if="index != numArr.length - 1"></div>
      </div>
    </div>
    <a-tabs type="card" default-active-key="1" @change="callback">
      <a-tab-pane key="1" tab="职位详情">
        <Position :dataJson="dataJson" />
      </a-tab-pane>
      <a-tab-pane key="4" tab="投递简历设置">
        <resumeDeliverySettings />
      </a-tab-pane>
      <a-tab-pane key="2" tab="经纪人" v-if="isBroker === 1">
        <economic :brokerRule="brokerRule" />
      </a-tab-pane>
      <a-tab-pane key="3" tab="内推" v-if="isEmp === 1">
        <mPush />
      </a-tab-pane>
    </a-tabs>
    <share :visible.sync="visible" :shareIdArr="shareIdArr" shareType="poster" />
  </div>
</template>

<script>
import rTitle from "../../component/rTitle";
import Position from "./component/position";
import share from "../../component/share";
import economic from "./component/economic/index";
import mPush from "./component/mPush/index";
import resumeDeliverySettings from "./component/resumeDeliverySettings";
import { getCompanyUnitsId, putCancelBatch, getFindByRecruitInfoId } from "../api";

export default {
  components: {
    rTitle,
    Position,
    share,
    economic,
    mPush,
    resumeDeliverySettings
  },
  data() {
    return {
      visible: false,
      shareIdArr: [],
      primaryColor: "",
      form: this.$form.createForm(this, {}),
      heights: 0,
      numArr: [
        // { type: "1", name: "待处理", num: 74 },
        { type: "1", name: "已投递", num: 0 },
        { type: "2", name: "已约面", num: 0 },
        { type: "3", name: "待入职", num: 0 },
        { type: "4", name: "已入职", num: 0 }
      ],
      dataJson: {},
      isCancel: 2,
      postName: "",
      brokerRule: "",
      isEmp: 2,
      isBroker: 2
    };
  },
  created() {
    this.onGetCompanyUnitsId();
    this.onGetFindByRecruitInfoId();
    this.primaryColor = localStorage.getItem("primary");
  },
  mounted() {},
  methods: {
    async onGetFindByRecruitInfoId() {
      try {
        const v = "/recruit2/api/v1/deliverRecords/findByRecruitInfoId/" + this.$route.query.id;
        const { data } = await getFindByRecruitInfoId(v);
        this.numArr[0].num = data.candidateCount || 0;
        this.numArr[1].num = data.faceToFaceCount || 0;
        this.numArr[2].num = data.toBeEmployedCount || 0;
        this.numArr[3].num = data.recruitedCount || 0;
      } catch (err) {
        console.log("error log --> ", err);
      }
    },
    async onGetCompanyUnitsId() {
      try {
        const v = "/recruit2/api/v1/recruitInfos/findById/" + this.$route.query.id;
        const { data } = await getCompanyUnitsId(v);
        this.dataJson = data;
        this.isCancel = data.isCancel;
        this.postName = data.postName;
        this.brokerRule = data.brokerRule;
        this.isEmp = data.isEmp;
        this.isBroker = data.isBroker;
      } catch (err) {
        console.log("error log --> ", err);
      }
    },
    callback() {},
    onShare() {
      this.visible = true;
      this.shareIdArr = [this.$route.query.id];
    },
    onEdit() {
      this.$router.push({ name: "managementEdit", query: { id: this.$route.query.id } });
    },
    async onPutCancelBatch() {
      try {
        const data = {
          isCancel: this.isCancel === 1 ? 2 : 1,
          recruitInfoIds: [this.$route.query.id]
        };
        await putCancelBatch(data);
        this.$notification.success({
          message: "提示",
          description: "操作成功"
        });
        this.onGetCompanyUnitsId();
      } catch (err) {
        console.log("error log --> ", err);
      }
    },
    close(v) {
      this.$confirm({
        okText: "确定",
        title: `确定要${v}？`,
        onOk: () => {
          this.onPutCancelBatch();
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.r-msg-box {
  padding: 24px;
  ::v-deep .ant-tabs-tab {
    margin-right: 12px !important;
  }
  .backBtn-box {
    width: calc(100% + 48px);
    height: 50px;
    margin: -24px 0 24px -24px;
    background: #f4f6fa;
  }
  .r-status {
    width: 46px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.25);
    color: #fff;
    border-radius: 2px;
    margin-top: 4px;
  }
  .r-msg-status {
    width: 100%;
    display: flex;
    justify-content: space-between;
    height: 100px;
    border-radius: 4px;
    border: 1px solid #e8e8e8;
    margin-top: 20px;
    margin-bottom: 24px;
    .s-item {
      width: 25%;
      box-sizing: border-box;
      padding-top: 24px;
      padding-left: 24px;
      position: relative;
      .s-item-t {
        color: #767885;
      }
      .s-item-b {
        font-size: 24px;
        font-weight: bold;
        color: #55565d;
      }
      .s-item-line {
        position: absolute;
        top: 32px;
        right: 0;
        width: 1px;
        height: 36px;
        background: #e8e8e8;
      }
    }
  }
}
</style>
